<html>
 <head>
  <title>Test Page for Services</title>
  <script language="javascript" src="../../jsunit/app/jsUnitCore.js"></script>
  <script language="javascript" src="../compiled/ca-all.js"></script>
 </head>
 <body>
  <script language="javascript">
    function testCreation() {
		var  aTest= {
			Test1:function(){}
		};
	    var success = false;
		try{
			CA.Services.Register("ITest1",aTest);
		}catch(e){
			success = true;
		}
		assertTrue("Should fail due to undefined interface",success);
	    CA.Interfaces.Create("ITest1", ["Test1","Test2"]);
		success = false;
		try{
			CA.Services.Register("ITest1",aTest);
		}catch(e){
			success = true;
		}
		assertTrue("Should fail due to service not providing the interface",success);
		aTest.Test2 = function(){};
		success = true;
		try{
			CA.Services.Register("ITest1",aTest);
		}catch(e){
			success = false;
		}
		assertTrue("Should succeed to add the service.",success);
		assertEquals("Should get the same object back.",aTest,CA.Services.Get("ITest1"));
		var o2 = {
			Test1 :function(){},
			Test2 : function(){}
		};
	    var success = false;
		try{
			CA.Services.Register("ITest1",o2);
		}catch(e){
			success = true;
		}
		assertTrue("Should fail due to service existing",success);		
	    var success = true;
		try{
			CA.Services.Register("ITest1",o2,null,true);
		}catch(e){
			success = false;
		}
		assertTrue("Should succeed as an override",success);
		assertNotEquals("Should get the new object back.",aTest,CA.Services.Get("ITest1"));
    }
  </script>
 </body>
</html>